﻿#region Usings

using System.Linq;
using System.Windows;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;

#endregion

namespace ScrumTable.UI.View.Ink
{
    /// <summary>
    /// ScrumStroke
    /// </summary>
    public class RectlangeStroke : ScrumStroke
    {

        #region Declarations
        //--------------------------------------------------------------------
        // Declarations
        //--------------------------------------------------------------------
   
        #endregion

        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------
        private const int NumberOfPointsForRectangle = 7;
        #endregion

        #region Constructors / Destructor
        //--------------------------------------------------------------------
        // Constructors / Destructor
        //--------------------------------------------------------------------

        public RectlangeStroke(Point from, Point to, DrawingAttributes attributes) : base(new StylusPointCollection(new [] { from, to }), attributes) { }

        #endregion




        #region Methods

        /// <summary>
        /// Packs the stroke to ink stroke.
        /// </summary>
        protected override void DrawCore(DrawingContext drawingContext, DrawingAttributes drawingAttributes)
        {
            StylusPoint first = StylusPoints.First();
            StylusPoint last = StylusPoints.Last();
            Rect rec = new Rect(new Point(first.X, first.Y), new Point(last.X, last.Y));
            
            //after packing -> no need for rectangle drawing
            if (StylusPoints.Count == NumberOfPointsForRectangle && StylusPoints[0] == StylusPoints[4])
            {
                base.DrawCore(drawingContext, drawingAttributes);
            }
            else
            {
                drawingContext.DrawRectangle(null, new Pen(new SolidColorBrush(drawingAttributes.Color), drawingAttributes.Height), rec);
            }

        }


        protected override StylusPointCollection Pack(Point from, Point to, double width, double height, StylusPointCollection collection)
        {
            collection.Add(new StylusPoint(from.X, from.Y));
            collection.Add(new StylusPoint(from.X + width, from.Y));
            collection.Add(new StylusPoint(from.X + width, from.Y + height));
            collection.Add(new StylusPoint(from.X, from.Y + height));
            collection.Add(new StylusPoint(from.X, from.Y));

            //needs for a correct rectangle
            collection.Add(new StylusPoint(from.X + width, from.Y));
            //adds the last point
            collection.Add(new StylusPoint(from.X + width, from.Y+height));
            
         
            return collection;
        }
        #endregion
        #region Events

        #endregion
    }
}
